home *** CD-ROM | disk | FTP | other *** search
/ Amiga Collections: Purity / Purity #23 (1994-02-10)(Diesel)(DE)[WB].zip / Purity #23 (1994-02-10)(Diesel)(DE)[WB].adf / DesignerDemo / toggledemo / ToggleDemo.pas < prev    next >
Pascal/Delphi Source File  |  1994-01-20  |  5KB  |  110 lines

  1. Program ToggleDemo;
  2.  
  3. {*****************************************************}
  4. {*                                                   *}
  5. {*   This demo shows how to ude Boolean type gadgets *}
  6. {*  to create mutually exclusive gadgets.            *}
  7. {*   When a Gadget is pressed it must de-select the  *}
  8. {*  other Gadgets and select itself.                 *}
  9. {*                                                   *}
  10. {*****************************************************}
  11.  
  12. Uses exec,intuition,gadtools,graphics,amiga,diskfont,
  13.      workbench,utility,toggledemowin;
  14.  
  15. const
  16.   FirstGad  : string = 'First Option'#0;
  17.   SecondGad : string = 'Second Option'#0;
  18.   ThirdGad  : string = 'Third Option'#0;
  19. var
  20.   done      : boolean;
  21.   class     : long;
  22.   code      : word;
  23.   pimsg     : pintuimessage;
  24.   dummy     : long;
  25.   pgsel     : pgadget;
  26.   gadnumber : word;
  27. begin
  28.   if openlibs then
  29.     begin
  30.       if makeimages then
  31.         begin
  32.           if openwindowmainwindow then
  33.             begin
  34.               done:=false;
  35.               repeat
  36.                 dummy:=wait(bitmask(mainwindow^.userport^.mp_sigbit));
  37.                 pimsg:=gt_getimsg(mainwindow^.userport);
  38.                 while(pimsg<>nil) do
  39.                   begin
  40.                     class:=pimsg^.class;
  41.                     code:=pimsg^.code;
  42.                     pgsel:=pgadget(pimsg^.iaddress);  { do not reference unless gadgetup or gadgetdown }
  43.                     gt_replyimsg(pimsg);
  44.                     gadnumber:=99;
  45.                     case class of
  46.                       idcmp_closewindow : 
  47.                         done:=true;
  48.                       idcmp_vanillakey :
  49.                         case upcase(chr(code)) of
  50.                           'F' : gadnumber:=FirstGadget;
  51.                           'S' : gadnumber:=SecondGadget;
  52.                           'T' : gadnumber:=ThirdGadget;
  53.                          end;
  54.                       idcmp_gadgetdown :
  55.                         gadnumber:=pgsel^.gadgetid;
  56.                      end;
  57.                     case gadnumber of
  58.                       FirstGadget :
  59.                         begin
  60.                           {* Remove gadgets from window *}
  61.                           RemoveGList(mainwindow,mainwindowglist,~0);
  62.                           {* Change Gadget Flags *}
  63.                           MainWindowGadgets[FirstGadget]->Flags  |= GFLG_Selected;
  64.                           MainWindowGadgets[SecondGadget]->Flags &= ~GFLG_Selected;
  65.                           MainWindowGadgets[ThirdGadget]->Flags  &= ~GFLG_Selected;
  66.                           /* Put Gadgets Back in window */
  67.                           AddGList(MainWindow,MainWindowGList,50,~0,NULL);
  68.                           /* Refresh Gadgets */
  69.                           RefreshGList(MainWindowGList,MainWindow,NULL,~0);
  70.                           GT_SetGadgetAttrs(MainWindowGadgets[DisplayGadget],MainWindow, GTTX_Text, "First Gadget", TAG_DONE);
  71.                         end;
  72.                       SecondGadget :
  73.                         begin
  74.                           dummy:=RemoveGList(mainwindow,mainwindowglist,~0);
  75.                           mainwindowgads[FirstGadget]^.Flags:=mainwindowgads[FirstGadget]^.Flags and ~GFLG_Selected;
  76.                           mainwindowgads[SecondGadget]^.Flags:=mainwindowgads[SecondGadget]^.Flags or GFLG_Selected;
  77.                           mainwindowgads[ThirdGadget]^.Flags:=mainwindowgads[ThirdGadget]^.Flags and ~GFLG_Selected;
  78.                           dummy:=AddGList(mainwindow,mainwindowglist,dummy,~0,nil);
  79.                           RefreshGList(mainwindowglist,mainwindow,nil,~0);
  80.                           gt_setsinglegadgetattr(mainwindowgads[DisplayGadget],mainwindow,
  81.                                                  GTTX_Text,long(@SecondGad[1]));
  82.                         end;
  83.                       ThirdGadget :
  84.                         begin
  85.                           dummy:=RemoveGList(mainwindow,mainwindowglist,~0);
  86.                           mainwindowgads[FirstGadget]^.Flags:=mainwindowgads[FirstGadget]^.Flags and ~GFLG_Selected;
  87.                           mainwindowgads[SecondGadget]^.Flags:=mainwindowgads[SecondGadget]^.Flags and ~GFLG_Selected;
  88.                           mainwindowgads[ThirdGadget]^.Flags:=mainwindowgads[ThirdGadget]^.Flags or GFLG_Selected;
  89.                           dummy:=AddGList(mainwindow,mainwindowglist,dummy,~0,nil);
  90.                           RefreshGList(mainwindowglist,mainwindow,nil,~0);
  91.                           gt_setsinglegadgetattr(mainwindowgads[DisplayGadget],mainwindow,
  92.                                                  GTTX_Text,long(@ThirdGad[1]));
  93.                         end;
  94.                      end;
  95.                     pimsg:=gt_getimsg(mainwindow^.userport);
  96.                   end;
  97.               until done;
  98.               closewindowmainwindow;
  99.             end
  100.            else
  101.             writeln('Could not open window.');
  102.           Freeimages;
  103.         end
  104.        else
  105.         writeln('Unable to make images.');
  106.       closelibs;
  107.     end
  108.    else
  109.     writeln('Could not open libraries.');
  110. end.